<?php
/*
	Aurus CMS - free OOP CMS
	Copyright (C) 2010  Nestor Yanchuk

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
if (isset($_POST['address'])) {
	$_POST['name'] = htmlspecialchars($_POST['name']);
	$file = "<?php
	\$config = array(
	'site_address' 	=>	 '{$_POST['address']}',
	'title' 	=>	 '{$_POST['name']}',
	'metadata' 	=>	 '',
	'furl' 	=>	 '1',
	'timeFormat' 	=>	 'l, H:i, d/m/Y',
	'language' 	=>	 '{$_POST['lang']}',
	'template' 	=>	 '{$_POST['tpl']}',
	'index_module' 	=>	 'news',
	'timeCorrection' 	=>	 '0',
	'editor' 	=>	 'bbcodes',
	);
	?>";
	
	if (file_put_contents(ROOT.'/engine/configs/config.main.php',$file)) {
		echo HEADER.'<h2>'.__('Файл конфігурації створено').'</h2><a href="'.LINK_ROOT.'install/index.php?step=9">'.__('Далі').'</a>'.FOOTER;
	} else {
		echo HEADER.__('Сталась помилка, записати файл конфігурацій не вдалось').FOOTER;
	}
	
} else {
	$langs = read_directory(ROOT.'/language/',1);
	
	$lselect = '<select name="lang">';
	foreach ($langs as $lng){
		$lselect .= '<option value="'.$lng.'">'.$lng.'</option>';
	}
	$lselect .= '</select>';
	
	$templates = read_directory(ROOT.'/templates/',1);
	$tselect = '<select name="tpl">';
	foreach ($templates as $template){
		$tselect .= '<option value="'.$template.'">'.$template.'</option>';
	}
	$tselect .= '</select>';
	
	echo HEADER.'<h2>'.__('Налаштування сайту').'</h2>'.form_start().Html::table(
	Html::tr(
	Html::td(__('Адреса сайту (Слеш в кінці обов\'язковий)')).
	Html::td('<input type="text" value="'.LINK_ROOT.'" name="address"/>')
	).Html::tr(
	Html::td(__('Назва сайту')).
	Html::td('<input type="text" value="Aurus" name="name"/>')
	).Html::tr(
	Html::td(__('Мова сайту')).
	Html::td($lselect)
	).Html::tr(
	Html::td(__('Шаблон сайту')).
	Html::td($tselect)
	)
	).'<input type="submit" value="'.__('Далі').'"/></form>'.FOOTER;
}